package com.test0109;

import java.util.ArrayList;
import java.util.List;

public class Test05 {
    public static void main(String[] args) {
        // (5)根据需求写出实现代码

        // 创建公司
        CC c = new CC("IBM");
        // 创建员工
        EE e1 = new EE("张三", 30, 3000);
        EE e2 = new EE("李四", 40, 4000);
        EE e3 = new EE("王五", 50, 5000);
        // 公司添加员工(集合)
        c.add(e1);
        c.add(e2);
        c.add(e3);
        c.add(new EE("赵六", 60, 6000));
        // 打印员工信息
        c.printAll();
        // 找出年龄最大员工
        EE x = c.m1();
        // 找出工资最低工资
        EE y = c.m2();
        // 找出李四员工
        EE z = c.m3("李四");
        // 求平均工资
        double d = c.m4();
        // 找工资高于平均工资的员工
        List list = c.m5();
    }
}
class CC{
    private String name;
    private List<EE> list = new ArrayList<>();

    public CC() {
    }

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "C{" +
                "name='" + name + '\'' +
                '}';
    }
    public void add(EE ee){
        list.add(ee);
    }
    public void add(String name, int age, double salary){
        list.add(new EE(name,age,salary));
    }
    public void printAll(){
        for(EE ee:list){
            System.out.println(ee);
        }
    }
    public EE m1(){
        EE max = list.get(0);
        for(EE ee:list){
            if(max.getAge()<ee.getAge()){
                max = ee;
            }
        }
        return max;
    }
    public EE m2(){
        EE min = list.get(0);
        for(EE ee:list){
            if(min.getSalary()>ee.getSalary()){
                min = ee;
            }
        }
        return min;
    }
    public EE m3(String name){
        for(EE ee:list){
            if(ee.getName().equals(name)){
                return ee;
            }
        }
        return null;
    }
    public double m4(){
        double sum = 0;
        for(EE ee:list){
            sum += ee.getSalary();
        }
        return sum/list.size();
    }
    public List m5(){
        List list1 = new ArrayList();
        double avg = m4();
        for(EE ee:list){
            if(ee.getSalary()>avg){
                list1.add(ee);
            }
        }
        return list1;
    }

}
class EE{
    private String name;
    private int age;
    private double salary;

    public EE() {
    }

    public EE(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "EE{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }
}